#pragma once

#include "ErrorModel.hpp"




namespace Engine
{
	namespace Edit
	{
		class MergedErrorModel
			: public QAbstractTableModel
		{
			Q_OBJECT

		public:

			SHARED(MergedErrorModel);

			MergedErrorModel();
			virtual ~MergedErrorModel();



			/**
			 * Adds the given model to this one.
			 */
			void add(ErrorModel::const_ptr model);

			/**
			 * Removes the given model from this one.
			 */
			void remove(ErrorModel::const_ptr model);

			/**
			 * @returns the number of rows with the given logger level
			 */
			int rowCount(logger::entry::Level lvl) const;



			/**
			 * @returns the window associated with the error of the given index
			 * @returns nullptr in case the index is not valid (or outside the bounds of this model)
			 */
			DocumentWindow* window(const QModelIndex& index) const;



			int rowCount(const QModelIndex& index = QModelIndex()) const;
			int columnCount(const QModelIndex& index = QModelIndex()) const;
			QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
			QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;

		protected slots:

			void onBeginResetModel();
			void onEndResetModel();

			void onBeginInsertRows(const QModelIndex& parent, int first, int last);
			void onEndInsertRows();

			void onBeginRemoveRows(const QModelIndex& parent, int first, int last);
			void onEndRemoveRows();

		protected:

			void updateNumbers();

		private:

			typedef std::vector<ErrorModel::const_ptr>    Models;
			typedef std::map<logger::entry::Level, int>   Counts;

			Models   m_models;
			Counts   m_counts;
		};
		///////////////////////////////////////////////////////////////////////////////////////////////////

	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
